using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;

namespace PageDraw
{
    [Serializable]
    class DrawBorder : DrawObject
    {
        public DrawBorder() { }
        public DrawBorder(string title, System.Drawing.Point loc, System.Drawing.Size size)
            : base(loc, size)
        {
            this.Title = title;
        }
        protected string title;

        [DescriptionAttribute("Border Title")]
        public string Title
        {
            get { return title; }
            set { title = value; AddAttribute("borderTitle", value); }
        }
        private int dxy = 3;
        private int dw = 5;
        public override void Draw(DrawArea drawArea, System.Drawing.Graphics g)
        {
            base.Draw(drawArea, g);
            if (!string.IsNullOrEmpty(title))
            {
                SizeF size = g.MeasureString(this.title, drawArea.Font);
                Point lu = new Point(x + dxy, y + dxy);
                Point ru = new Point(x + width - dxy, y + dxy);
                Point ld = new Point(x + dxy, y + height - dxy);
                Point rd = new Point(x + width - dxy, y + height - dxy);

                Point lm = new Point(x + dw, y + dxy);
                Point rm = new Point(x + dw + (int)size.Width, y + dxy);
                Point sl = new Point(x + dw, y);

                g.DrawLines(Pens.Black, new Point[] { lu, ld, rd, ru });
                if (size.Width <= width)
                {
                    g.DrawString(this.title, drawArea.Font, Brushes.Black, sl);
                }
                else
                {
                    string rt = "...";
                    size = g.MeasureString(rt, drawArea.Font);
                    rm = new Point(x + dw + (int)size.Width, y + dxy);
                    g.DrawString(rt, drawArea.Font, Brushes.Black, sl);
                }
                g.DrawLine(Pens.Black, rm, ru);
                g.DrawLine(Pens.Black, lu, lm);
            }
            else
            {
                g.DrawRectangle(Pens.Black, x, y, width, height);
            }
        }

    }
}
